
const path = require('path')
const fs = require('fs')
const { defineConfig } = require('@vue/cli-service')

// const cinemasMock = require('./mock/cinema')

// 列表
const mocks = []
// 得到mock目录路径 绝对路径
const mockPath = path.resolve('./src/mock')
// 读取目录下面的.js文件
const files = fs.readdirSync(mockPath)
files.forEach(fileName => {
  mocks.push(require(path.join(mockPath, fileName)))
})

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,

  // 开发时服务器设置 https://webpack.docschina.org/configuration/dev-server/
  // 请求的地址一定是同域下，然后它才能拦截，才能进行代理处理
  // express服务器
  devServer: {
    setupMiddlewares: (middlewares, { app }) => {
      mocks.forEach(fn => fn(app))

      return middlewares
    },
  }
})
